package com.example.demo.newthread;

import java.time.LocalDateTime;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * ClassName: CallableDemo
 * author: bob.ly
 * Version: 1.0.0
 * DateTime: 2021/07/31-20:32:00
 * Description:
 */
public class CallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println(LocalDateTime.now());
        /**
         * 假设访问订单接口需要2秒
         */
        FutureTask<String> order = new FutureTask(() -> {
            Thread.sleep(2000);
            return "订单接口";
        });
        /**
         * 假设访问订单接口需要3秒
         */
        FutureTask<String> pay = new FutureTask(() -> {
            Thread.sleep(3000);
            return "支付接口";
        });
        new Thread(order).start();
        new Thread(pay).start();
        System.out.println("主线程属于用户模块");
        System.out.println(pay.get());
        System.out.println(order.get());
        System.out.println(LocalDateTime.now());
    }
}
